<!DOCTYPE html>
<html lang="en">
<head>
	<meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, maximum-scale=1, user-scalable=no" charset="UTF-8">
	<link rel="stylesheet" href="android_asset://css/style.css"/>
    <link rel="stylesheet" href="android_asset://css/font.css"/>
	<title>完成</title>
</head>
<body>
	<div class="complete">
	    <form id="form" action="/tickets/{{ticketId}}/finish">
	    <input type="hidden" name="action" value="finish"> 
		<input type="hidden" name="ticketid" value="{{ticketId}}">
		<div class="items marbot">
			<div class="item">
				<h4>最终服务客户</h4>
				<div class="listing">
					<p class="borderbot">联系人
					  <a href="#" class="right">
					  	<input id="actuallcustomer" name="actuallcustomer" type="text" placeholder="填写联系人姓名" maxLength="12">
					  </a>
					</p>
					<p>电话
					  <a href="#" class="right">
						<input name="actuallcustomerphone" id="actuallcustomerphone" type="tel" placeholder="填写联系人电话" maxLength="16">
					  </a>	
				    </p>
				</div>
			</div>
			<div class="item">
				<h4>更换备件</h4>
				<div class="listing">
					<div class="clearfix borderbot">
						<p class="left">换上件</p>
						<ul class="up">
							<li><span class='icon-add' onclick="upPartMenu()"></span></li>
						</ul>
					</div>

					<div class="clearfix">
						<p class="left">换下件</p>
						<ul class="down">
							<li><span class='icon-add' onclick="downPartMenu()"></span></li>
						</ul>
						<i class="right">点击加号添加</i>
					</div>
				</div>
			</div>

			<div class="item">
				<h4>上传凭证<span>工单凭证和电子签名，至少要提交一项</span></h4>
				<div class="listing">
					<div class="clearfix borderbot">
						<p class="left">工单凭证</p>
						<ul id="work-ul">
							<li><span class='icon-add' onclick="workUl()"></span></li>
						</ul>
					</div>

					<div class="clearfix">
						<p class="left">电子签名</p>
						<ul id="el-ul">
							<li><span class='icon-add' onclick="elUl()"></span></li>
						</ul>
						<i class="right">点击加号添加</i>
					</div>
				</div>
			</div>

			<div class="item">
				<h4>解决方案</h4>
				<div class="text">
					<textarea name="solution_summary" cols="30" rows="5" style="width:100%;" placeholder="填写本次维修过程的解决方案..."></textarea>
		    	</div> 
			</div> 
		</div> 	 
		</form>
		<div class="confirm_import" style="position:fixed;">
			<button type="button" class="but"><a href="javascript:void(0);">确认</a></button>
		</div>
	</div>
</body>
<script src="android_asset://jquery-1.11.0.min.js" type="text/javascript"></script>
<script src="android_asset://jquery-migrate-1.2.1.min.js" type="text/javascript"></script>
<script src="android_asset://jquery.touchSwipe.min.js" type="text/javascript"></script>
<script src="android_asset://bridge.js" type="text/javascript"></script>
<script src="android_asset://android.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
	  $('button.but').on('keydown touchstart', function () {
  		  $(this).css("background", '#216cb9');
  	  });
  	  $('button.but').on('keyup touchend', function () {
  	      $(this).css("background", '#3e8ddd');
  	  });
});

var attId=0;
//加载图片
function partMenu(picker,attType){
	if(msAndroid[picker]==null||msAndroid[picker]<0){
		msAndroid[picker]=0
	}
	var menu=[{text:"拍照录入",index:0},
	          {text:"手动录入",index:1}
	         ];
	msAndroid.menu(menu,function(response){
		var obj=eval('('+response+')');
		if(obj.status==1){
			if(obj.data.index==0){
				msAndroid.picture(picker,attType,null,false);
			}else if(obj.data.index==1){
				msAndroid.get("/tickets/deviceInput?picker="+picker,true);
			}
		}else{
			toast(obj.message);
		}
	},msAndroid[picker]);
}
//添加节点
function deviceInput(obj){
	var name=obj.picker.replace("\.","");
	var objStr="";
	for(var key in obj){
		objStr+="&"+key+"="+obj[key];
	}
	var li="<li id='att"+attId+"' class='listing_li' onclick=msAndroid.get('/tickets/deviceInfo?attId=att"+attId+objStr+"',true) >"+
	       "<span class='icon-device'></span><b>"+obj.name+"</b><input type='hidden' name='"+name+"' value='"+JSON.stringify(obj)+"'></li>";
	$(obj.picker).append(li);
    attId++;
}
//删除节点
function delDevice(id){
	$("#"+id.attId).remove();
}
//换上件
function upPartMenu(){
	var upCount = $(".up img").length+($(".up span").length-1);
	if(upCount>=20){
		 msAndroid.toast("换上件的记录不能超过20条");
		 return;
	}
	partMenu('.up',4);
}
function showButton(){
	   $("div.confirm_import").css("position"," fixed");
}
//换下件
function downPartMenu(){
	var downCount = $(".down img").length+($(".down span").length-1);
	if(downCount>=20){
		 msAndroid.toast("换下件的记录不能超过20条");
		 return;
	}
	partMenu('.down',5)
}
//工单凭证
function workUl(){
	var work_ul = $("#work-ul img").length;
	if(work_ul>=20){
		 msAndroid.toast("工单凭证最多20张");
		 return;
	}
	msAndroid.picture('#work-ul',3,null,false);
	
}
//电子签名
function elUl(){
	var el_ul = $("#el-ul img").length;
	if(el_ul>=4){
		 msAndroid.toast("电子签名最多4张");
		 return;
	}
	msAndroid.picture('#el-ul',0,null,null,true)
}

   function showButton(){
	   $("div.confirm_import").css("position"," fixed");
   }
   

$(function(){
	//文本框编辑时 确定按钮不随键盘移动
	$("#actuallcustomerphone").focus(function(){
    	$("div.confirm_import").css("position","");
    });
    $("#actuallcustomerphone").blur(function(){
    	$("div.confirm_import").css("position"," fixed");
    });
    $("#actuallcustomer").focus(function(){
    	$("div.confirm_import").css("position","");
    });
    $("#actuallcustomer").blur(function(){
    	$("div.confirm_import").css("position"," fixed");
    });
    $("#solution_summary").focus(function(){
    	$("div.confirm_import").css("position","");
    });
    $("#solution_summary").blur(function(){
    	$("div.confirm_import").css("position"," fixed");
    });

	$(".confirm_import button").click(function(){
		//验证用户名非空
		if($("#actuallcustomer").val().length==0){
			 msAndroid.toast("请输入联系人姓名");
			 return ;
		}
		//验证电话和手机联系方式
		var actuallcustomerphone = $("#actuallcustomerphone").val();
		var regTel = /^([0-9]|[-])+$/.test(actuallcustomerphone);
		if(!regTel){
		 msAndroid.toast("请输入正确的联系电话");
		 return ;
		};
	/* 	//验证电话和手机联系方式
		var mobile = $.trim($("#actuallcustomerphone").val());  
        var isMobile = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1})|(14[0-9]{1}))+\d{8})$/;  
        var isPhone = /^(?:(?:0\d{2,3})-)?(?:\d{7,8})(-(?:\d{3,}))?$/;
        //如果为1开头则验证手机号码  
        if (mobile.substring(0, 1) == 1) {  
            if (!isMobile.exec(mobile) && mobile.length != 11) {  
            	msAndroid.toast("请正确填写电话号码，例如:13511111111或010-11111111");
                $("#actuallcustomerphone").focus();  
                return false;  
            }  
        }  
        //如果为0开头则验证固定电话号码  
        else if (mobile.substring(0, 1) == 0) {  
            if (!isPhone.test(mobile)) {  
            	msAndroid.toast("请正确填写电话号码，例如:13511111111或010-11111111");
                $("#actuallcustomerphone").focus();  
                return false;  
            }  
        }  
        //否则全部不通过  
        else { 
        	msAndroid.toast("请正确填写电话号码，例如:13511111111或010-11111111");
            $("#actuallcustomerphone").focus();  
            return false;  
        }  */
		//验证换上换下件
		var upCount = $(".up img").length+($(".up span").length-1);
		var downCount = $(".down img").length+($(".down span").length-1);
		if(upCount>20){
			 msAndroid.toast("换上件的记录不能超过20条");
			 return;
		}
		if(downCount>20){
			 msAndroid.toast("换下件的记录不能超过20条");
			 return;
		}
		if((upCount==0&downCount!=0)|(upCount!=0&downCount==0)){
			 msAndroid.toast("换下件或换下件没有录入");
			 return;
		}
		//验证电子签名和工单凭证
		var el_ul = $("#el-ul img").length;
		var work_ul = $("#work-ul img").length;
		if(el_ul==0&&work_ul==0){
			msAndroid.toast("工单凭证和电子签名至少上传一种");
			 return;
		}
		
		//验证解决方案
		var solution_summary = $("#form :input[name='solution_summary']").val();
		if(solution_summary.length<10|solution_summary.length>500){
			 msAndroid.toast("请输入10~500字的解决方案");
			 return;
		}
		var formJson=msAndroid.changedTicketVO("#form");
		var url=$("#form").attr("action");
		var attJson=msAndroid.attVO("#form");

		if(attJson.original!=null){
			msAndroid.post("/tickets/{{ticketId}}/attachments/info",attJson,"post");
		}
		var btn = this;
		msAndroid.post(url,formJson,"put","active",function() {
			btn.disabled = false;
		});
		//禁止页面二次提交
	 	btn.disabled = true;
	});
})
</script>
</html>